<% include ../header.ejs %>
<div class="row">
    <div class="col-md-12">
        <div class="box box">
            <div class="box-header with-border">
                <h3 class="box-title">栏目列表</h3>

                <!-- todo -->
<!--                 <div class="box-form">
                    <hr>
                    <form class="form-inline" method="get">
                        <div class="form-group">
                            <label for="keywords">关键词类型：</label>
                            <select name="type" class="form-control">
                                <option value="username" <%if(req.query.type == "username"){%> selected <%}%>>用户名</option>
                                <option value="email" <%if(req.query.type == "email"){%> selected <%}%>>邮箱</option>
                                <option value="id" <%if(req.query.type == "id"){%> selected <%}%>>ID</option>
                            </select>    
                            <input type="text" name="keywords" class="form-control" value="<%-req.query.keywords%>" >
                        </div>
                        <button type="submit" class="btn btn-warning">搜 索</button>
                    </form>
                </div> -->
            </div>
            <div class="box-body dataTables_wrapper form-inline dt-bootstrap" >
                <div class="row">
                    <div class="col-sm-12">
                        <div class="row clearfix">
                            <div class="col-sm-12">
                                <button href="/admin/category/d_add" class="btn  btn-primary btn-form">添加栏目</button>
                            </div>
                        </div>
                        <hr>
                        <table  class="table table-bordered table-striped dataTable" role="grid" >
                            <thead>
                                <tr role="row">
                                    <th>ID</th>
                                    <th>标题</th>
                                    <th>栏目模型</th>
                                    <th>栏目别名</th>
                                    <th>导航显示</th>
                                    <th>操作</th>
                                </tr>
                            </thead>    
                            <tbody>
                                <%
                                    var deep = 0;
                                    var line = "";
                                    function nestPrint(data){
                                        data.forEach(function(one,key){
                                            line += '<tr role="row" class="color-palette">\
                                                <td>'+one.id+'</td>\
                                                <td>'+one.name+'</td>\
                                                <td>'+__("model_"+one.model)+'</td>\
                                                <td>'+one.dir+'</td>\
                                                <td>'+__(String(one.isnavigation))+'</td>\
                                                <td>\
                                                    <a class="btn-form" href="/admin/category/d_update/'+one.id+'">编辑</a>\
                                                    <a href="/admin/category/delete/'+one.id+'" onclick="if(!confirm(\'删除后不可恢复,确定删除纪录吗?\'))return false;">删除</a>\
                                                </td>\ 
                                            </tr>\r\n';
                                            if(one.children){
                                                nestPrint(one.children);
                                            }
                                        });
                                        return line;
                                    }
                                    nestPrint(data);
                                %>
                                <%-line%>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- jquery 表单异步提交 -->
<script type="text/javascript" src="/lib/jquery.form.js"></script>
<script type="text/javascript">
$(document).on("submit",".ajax_form form",function () {
    $(".ajax_form form").ajaxSubmit({
        success: function (data) {
        if(typeof data === "object" && data.result){
            window.location.reload();
        }
        if(typeof data === "string"){
                $(".ajax_form").replaceWith(data);
            }
        }
    });
    return false;
});
</script>
<% include ../footer.ejs %>